<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
       function kiemtra(){
            var rollno = document.form1.txtrollno;
            var name = document.form1.txtstname;
            var address = document.form1.txtaddress;
            var phone = document.form1.txtphone;
            var email = document.form1.txtemail;
            if( laChuoiRong(rollno.value))
            {
                alert('Rollno is not blank!');
                rollno.focus();
                return false;
            }
            if( laChuoiRong(name.value))
            {
                alert('Full name is not blank!');
                name.focus();
                return false;
            }
            if( laChuoiRong(address.value))
            {
                alert('Address is not blank!');
                address.focus();
                return false;
            }
            if( laChuoiRong(phone.value))
            {
                alert('Phone is not blank!');
                phone.focus();
                return false;
            }
            if( laChuoiRong(email.value))
            {
                alert('Email is not blank!');
                email.focus();
                return false;
            }
            if(!laSoNguyen(phone.value))
            {
                alert('Phone is number!');
                phone.focus();
                return false;
            }
            if( !laEmail(email.value) )
            {
                alert('Email invalid!, Ex: jhon@gmail.com');
                email.focus();
                return false;
            }
       }
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        String r="";String n="";String g=""; String a=""; String p=""; String m="";
        if(session.getAttribute("roll")!=null){
            r=session.getAttribute("roll").toString();
            n=session.getAttribute("name").toString();
            g=session.getAttribute("gen").toString();
            a=session.getAttribute("addrss").toString();
            p=session.getAttribute("pho").toString();
            m=session.getAttribute("mail").toString();
        }
        %>
        <form action="../ControllStudent" name="form1" method="Post" onsubmit="return kiemtra()">
            <h3 align="center">Student Management</h3>
            <table>
                <tr>
                    <td>Rollno:</td>
                    <td><input type="text" name="txtrollno" value="<%=r%>" /></td>
                    <input type="hidden" name="tmp" value="<%=r%>" />
                </tr>
                <tr>
                    <td>Student Name:</td>
                    <td><input type="text" name="txtstname" value="<%=n%>" /></td>
                </tr>
                <tr>
                    <td>Address:</td>
                    <td><textarea name="txtaddress" rows="5" cols="20"><%=a%>
                    </textarea></td>
                </tr>
                <tr>
                    <td>Phone:</td>
                    <td><input type="text" name="txtphone" value="<%=p%>" /></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><input type="text" name="txtemail" value="<%=m%>" /></td>
                </tr>
                <tr>
                    <td>Gender:</td>
                    <td>
                        <%if(g==""){%>
                        Male<input type="radio" name="rdgender" value="Male" checked="true" />
                        Female<input type="radio" name="rdgender" value="Female"/>
                        <%}%>
                        <%if(g.equals("Male")){%>
                        Male<input type="radio" name="rdgender" value="Male" checked="true" />
                        Female<input type="radio" name="rdgender" value="Female"/>
                        <%}%>
                        <%if(g.equals("Female")){%>
                        Male<input type="radio" name="rdgender" value="Male"/>
                        Female<input type="radio" name="rdgender" value="Female" checked="true" />
                        <%}%>
                    </td>
                </tr>
                
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" name="bt" value="Insert" />
                        <input type="submit" name="bt" value="Update" />
                        <input type="button" name="btreset" value="Reset" onclick="clear_fields()" />
                    </td>
                </tr>
            </table>
            <%
            StudentBean ojb=new StudentBean();
            Collection kq=ojb.getListStudent();
            request.setAttribute("st", kq);
            %>
            
            <table border="1">
                <tr>
                    <td colspan="8"><a href="indexAdmin.jsp?page=Admin&url=SearchStudent">Search Student</a></td>
                </tr>
                <tr>
                    <th>Rollno</th>
                    <th>Student Name</th>
                    <th>Gender</th>
                    <th>Address</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th colspan="2">Action</th>
                    
                </tr>
                <pg:paging pageSize="10" url="indexAdmin.jsp?page=Admin&url=Student"> 
                    <c:forEach items="${st}" var="s">
                        <pg:item> 
                            <tr>
                                <td><c:out value="${s.rollno}" /></td>
                                <td>${s.stname}</td>
                                <td>${s.gender}</td>
                                <td>${s.address}</td>
                                <td>${s.phone}</td>
                                <td>${s.email}</td>
                                <c:url var="delete" value="../ControllStudent">
                                    <c:param name="bt" value="Delete" />
                                    <c:param name="rollno" value="${s.rollno}" />
                                    <c:param name="p" value="${param.pageNum}"/> 
                                </c:url>
                                <c:url var="edit" value="../ControllStudent">
                                    <c:param name="bt" value="Edit" />
                                    <c:param name="rollno" value="${s.rollno}" />
                                    <c:param name="stname" value="${s.stname}" />
                                    <c:param name="gender" value="${s.gender}" />
                                    <c:param name="address" value="${s.address}" />
                                    <c:param name="phone" value="${s.phone}" />
                                    <c:param name="email" value="${s.email}" />
                                    <c:param name="p" value="${param.pageNum}"/> 
                                </c:url>
                                <% if(session.getAttribute("permission")!=null){
                                    if(session.getAttribute("permission").equals("Academic")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                <%    
                                    }
                                %>
                                <% 
                                    if(session.getAttribute("permission").equals("Admin")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                    <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                                <%    
                                    }
                                %>
                                <%}%>
                            </tr>
                        </pg:item>
                    </c:forEach>
                    <pg:index>
                            <pg:page><%=thisPage%></pg:page>
                            <pg:firstPage>[First]</pg:firstPage>
                            <pg:lastPage>[Last]</pg:lastPage> 
                        </pg:index> 
                </pg:paging>
            </table>
        </form>
    </body>
</html>
<%}%>
